package com.lefeng.cockpit.common.enums;

import com.didiglobal.logi.security.exception.CodeMsg;
import io.swagger.annotations.ApiModel;

/**
 * 规定: #1表示成功
 * #1001～1999 区间表示参数错误
 * #2001～2999 区间表示用户错误
 * #3001～3999 区间表示接口异常
 */
@ApiModel(value = "返回说明")
public enum ResultCode implements CodeMsg {
    UNSUPPORTED_DB_TYPE(3200, "不支持的数据库类型"),
    CONNECTION_FAILED(3201, "数据库用户名或者密码错误，请检查填写的账号密码"),
    ;

    private final Integer code;

    private final String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    /**
     * 根据code获取message.
     *
     * @param code taskCode
     * @return str
     */
    public static String getMessageByCode(Integer code) {
        for (ResultCode ele : values()) {
            if (ele.getCode().equals(code)) {
                return ele.getMessage();
            }
        }
        return null;
    }
}
